package br.com.infocruz.seam.crm.ejb.session;

import org.jasypt.encryption.pbe.StandardPBEStringEncryptor;
import org.jasypt.encryption.pbe.config.EnvironmentPBEConfig;
import org.jasypt.hibernate.encryptor.HibernatePBEEncryptorRegistry;
import org.jasypt.salt.RandomSaltGenerator;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Observer;
import org.jboss.seam.log.Log;

@Name("initializer")
public class Initializer {

	@Logger
	Log log;

	@Observer("org.jboss.seam.postInitialization")
	public void initializeJasypt() {
		log.info("Initializing Jasypt String Encryptor");
		StandardPBEStringEncryptor strongEncryptor = new StandardPBEStringEncryptor();
		EnvironmentPBEConfig config = new EnvironmentPBEConfig();
		//		config.setPasswordEnvName("jasypt_password");
		config.setSaltGenerator(new RandomSaltGenerator());
		config.setPasswordSysPropertyName("jasypt_password");
		config.setPassword("mzwG/b4h6Zz5BKTaE4ZRqw==");
		strongEncryptor.setConfig(config);
		HibernatePBEEncryptorRegistry registry = HibernatePBEEncryptorRegistry.getInstance();
		registry.registerPBEStringEncryptor("myHibernateStringEncryptor", strongEncryptor);
	}
}
